<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
<script>
    
    //1.创建XMLHttpRequest实例
    let xhr4 = new XMLHttpRequest();
    //2.打开连接  表示对http://localhost:3000/users发送POST请求，异步方式
    xhr4.open('DELETE','/users?id=1',true);
     //设置了响应体的类型是json,服务器返回的响应体是什么格式，这里要指定成什么样式
    //xhr3.responseType = 'json';
    //指定请求体内容的类型，这是一个请求头
    //xhr4.setRequestHeader('Content-Type','application/json');
    //2.注册当状态变化时回调函数
    xhr4.onreadystatechange = function(){
        if(xhr4.readyState===xhr4.DONE && (/^2\d{2}$/.test((xhr4.status)))){
            //获取所有的响应头
            console.log(xhr4.getAllResponseHeaders())
            //获取响应体
            console.log(xhr4.responseText);
        }
    }
    xhr4.send();
</script>
</body>
</html>